package com.ads.tpgrupo4.server.utils;

import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;

public class XmlUtils {
	
	public static Document getDocumentFromFilePath(final String filePath) throws Exception {
		
		final DocumentBuilder builder = newDocumentBuilder();
		final Document doc = builder.parse(filePath);
		
		return doc;
	}
	
	public static Document getDocumentFromInputStream(final InputStream inputStream) throws Exception {
		
		final DocumentBuilder builder = newDocumentBuilder();
		final Document doc = builder.parse(inputStream);
		
		return doc;		
	}
	
	private static DocumentBuilder newDocumentBuilder()
			throws ParserConfigurationException {
		
		final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		final DocumentBuilder builder = factory.newDocumentBuilder();
		
		return builder;
	}

}
